      <template>
          <section>
              <div>
            <el-table :data="SearchStatus" style="width: 100%">
                <el-table-column type="index" align="center" label="编号"></el-table-column>
                <el-table-column prop="states"align="center" label="审核状态" :formatter="formatState"></el-table-column>
                <el-table-column prop="date" align="center" label="审核时间"></el-table-column>
                <el-table-column label="操作" width="150" >
                    <template slot-scope="scope">
                        <el-button @click="QueryClick()"size="mini">查询状态</el-button>
                        <el-button @click="updateClick(scope.index,scope.row)" type="text" size="mini">修改</el-button>
                    </template>
                </el-table-column>
            </el-table>
             <!--查询状态-->
              <el-dialog title="状态查询" :visible.sync="statusDialogVisible"  width="30%">
                  <!--查询弹窗-->
                  <el-form v-model="queryStatusForm"  label-width="100px">
                      <el-form-item label="商家名称" prop="username">
                          <el-input v-model="queryStatusForm.username"></el-input>
                      </el-form-item>
                      <el-form-item label="审阅状态" prop="state">
                          <el-radio-group v-model="queryStatusForm.state">
                              <el-radio class="radio" :label=1>审核通过</el-radio>
                              <el-radio class="radio" :label=0>待审核</el-radio>
                              <el-radio class="radio" :label=-1>驳回</el-radio>
                          </el-radio-group>
                      </el-form-item>
                      <el-form-item label="审核原因" prop="username">
                          <el-input v-model="queryStatusForm.reson"></el-input>
                      </el-form-item>
                      <el-form-item label="审核时间" prop="username">
                          <el-input v-model="queryStatusForm.date"></el-input>
                      </el-form-item>
                  </el-form>
              </el-dialog>
            <!--增加和修改模态框-->
          <!--:model="shop" 数据双向绑定-->
          <!--ref="shopForm" id="shopForm",给form去一个名字-->
          <!--:rules="formRules" 校验规则-->
          <el-dialog title="修改" :visible.sync="updatedialogVisible"  width="30%">
          <el-form :model="shop" ref="shopForm" :rules="formRules" label-position="left" label-width="100px" class="demo-ruleForm login-container">
              <h3 class="title">店铺入驻</h3>
              <el-form-item prop="name"label="名称">
                  <el-input type="text" v-model="shop.name" auto-complete="off" placeholder="请输入店铺名称！"></el-input>
              </el-form-item>
              <el-form-item prop="tel" label="座机">
                  <el-input type="text" v-model="shop.tel" auto-complete="off" placeholder="请输入座机！"></el-input>
              </el-form-item>
              <el-form-item prop="address" label="店铺地址">
                  <el-input type="text" style="width: 350px" v-model="shop.address" auto-complete="off" placeholder="请输入地址！"></el-input>
                  <!--        <el-button size="small" type="primary" @click="selectAdrress">选择</el-button>-->
              </el-form-item>
              <el-form-item prop="logo" label="店铺Logo">
                  <el-upload
                          class="upload-demo"
                          action="http://localhost/fastDfs"
                          :on-preview="handlePreview"
                          :on-remove="handleRemove"
                          :on-success="handleSuccess"
                          :file-list="fileList"
                          list-type="picture">
                      <el-button size="small" type="primary">点击上传</el-button>
                      <div slot="tip" class="el-upload__tip">只能上传jpg/png文件，且不超过500kb</div>
                  </el-upload>
              </el-form-item>
              <h3>管理员信息设置</h3>
              <el-form-item prop="username" label="账号">
                  <el-input type="text" v-model="shop.username" auto-complete="off" placeholder="请输入账号！"></el-input>
              </el-form-item>
              <el-form-item prop="tel" label="手机号码">
                  <el-input type="text" v-model="shop.phone" auto-complete="off" placeholder="请输入电话！"></el-input>
              </el-form-item>
              <el-form-item prop="email" label="电子邮件">
                  <el-input type="text" v-model="shop.email" auto-complete="off" placeholder="请输入邮件！"></el-input>
              </el-form-item>
              <el-form-item prop="password" label="密码">
                  <el-input type="password" v-model="shop.password" auto-complete="off" placeholder="请输入密码！"></el-input>
              </el-form-item>
              <el-form-item prop="comfirmPassword" label="确认密码">
                  <el-input type="password" v-model="shop.comfirmPassword" auto-complete="off" placeholder="请输入确认密码！"></el-input>
              </el-form-item>
              <el-form-item style="width:100%;">
                  <el-button type="primary" style="width:100%;" @click.native.prevent="settledIn" >入驻</el-button>
              </el-form-item>

          </el-form>
          </el-dialog>

          <el-dialog
                  title="选择地址"
                  :visible.sync="dialogVisable"
                  width="30%">
              <baidu-map :center="{lng: 116.403765, lat: 39.914850}" :zoom="11">
                  <bm-view class="map"></bm-view>
                  <bm-control :offset="{width: '10px', height: '10px'}">
                      <!--:sugStyle="{zIndex: 2100} 让搜索提示上浮-->
                      <bm-auto-complete v-model="keyword" :sugStyle="{zIndex: 2100}">
                          <div style="margin-bottom:10px">
                              <input id="searchInput" type="text" placeholder="请输入关键字" class="searchinput"/>
                              <el-button type="success" @click="selectAdrressConfirm">确定</el-button>
                          </div>
                      </bm-auto-complete>
                  </bm-control>
                  <bm-local-search :keyword="keyword" :auto-viewport="true" ></bm-local-search>
              </baidu-map>
              <span slot="footer" class="dialog-footer">
            <el-button @click="dialogVisable=false">取 消</el-button>
            <el-button type="primary" @click="dialogVisable=false">确 定</el-button>
          </span>
         </el-dialog>
       </div>
    </section>
</template>

<script>
    export default {
        data() {
            return {
                keyword:'',
                fileList: [],
                updatedialogVisible:false,
                SearchStatus:[],
                dialogVisable:false,
                statusDialogVisible:false,
                queryStatusForm:{
                    username:"",
                    state:"",
                    reson:"",
                    date:"",
                },
                shop: {
                    name: '',
                    tel: '',
                    address: '',
                    logo:'',
                    username:'',
                    tel:'',
                    phone:'',
                    email:'',
                    password:'',
                    comfirmPassword:''
                },
                formRules: {
                    name: [
                        { required: true, message: '请输入店铺名称!', trigger: 'blur' }
                    ],
                    tel: [
                        { required: true, message: '请输入店铺座机!', trigger: 'blur' }
                    ],
                    address: [
                        { required: true, message: '请输入店铺地址!', trigger: 'blur' }
                    ]
                    // logo: [
                    //     { required: true, message: '请输入店铺logo!', trigger: 'blur' }
                    // ],
                    /* username: [
                         { required: true, message: '请输入账号!', trigger: 'blur' }
                     ],
                     tel: [
                         { required: true, message: '请输入座机!', trigger: 'blur' }
                     ],
                     phone: [
                         { required: true, message: '请输入手机号!', trigger: 'blur' }
                     ],
                     // email: [
                     //     { type: 'email',required: true, message: '请输入邮箱!', trigger: 'blur' }
                     // ],
                     password: [
                         { required: true, message: '请输入密码!', trigger: 'blur' }
                     ],
                     comfirmPassword: [
                         {required: true,validator: validatePass2, trigger: 'blur' } //自定义校验规则
                     ]*/
                },
            }
        },
        methods:{
            selectAdrressConfirm(){
                //获取值搜索框值,设置给地址
                var searchInputV=document.getElementById("searchInput").value;
                this.shop.address = searchInputV;
                //关闭对话框
                this.dialogVisable = false;
            },
            selectAdrress(){
                this.dialogVisable = true;
            },
            handleSuccess(response, file, fileList){
                console.log("===========")
                console.log("!!!!!!!!!!!!!!!!!!!!",response);
                console.log(file);
                console.log(fileList);
                this.shop.logo = response.result;
            },handleRemove(file, fileList) {
                console.debug("-=============",file)
                //var filePath =file.response.resultObj;
                this.$http.delete("/common/fastDfs/?path="+filePath)
                    .then(res=>{
                        if(res.data.success){
                            this.$message({
                                message: '删除成功!',
                                type: 'success'
                            });
                        }else{
                            this.$message({
                                message: '删除失败!',
                                type: 'error'
                            });
                        }
                    })
            },
            handlePreview(file) {
                console.log("---------------",file);
            },
            formatState(){
                this.states==1?"通过审核":(this.states==0?"待审核":"驳回");
            },
            QueryClick(row){
                this.statusDialogVisible=true;
                for (var k in row){

                }
            },
            settledIn(){
                this.$refs.shopForm.validate((valid) => {
                    //校验表单成功后才做一下操作
                    if (valid) {
                        this.$confirm('确认入驻吗？', '提示', {}).then(() => {
                            //拷贝后面对象的值到新对象,防止后面代码改动引起模型变化
                            let para = Object.assign({}, this.shop); //shop 本身这个参数里面就有店铺和管理员信息
                            // 为了后台好接收，封装一个对象放到里面
                            let admin = {
                                username: para.username,
                                phone: para.phone,
                                email: para.email,
                                password:para.password,
                                comfirmPassword:para.comfirmPassword
                            }
                            para.admin = admin;
                            //判断是否有id有就是修改,否则就是添加
                            this.$http.post("http://localhost/shop/settledIn",para).then((res) => {
                                if(res.data.success){
                                    this.$message({
                                        message: '操作成功!',
                                        type: 'success'
                                    });
                                    //重置表单
                                    this.$refs['shopForm'].resetFields();
                                    //跳转登录页面
                                    this.$router.push({ path: '/login' });
                                }
                                else{
                                    this.$message({
                                        message: res.data.message,
                                        type: 'error'
                                    });
                                }

                            });
                        });
                    }
                })
            },
            //修改
            updateClick(index,row){

            }

        },

        mounted(){
            //this.loadShopMessage();
        }
    }
</script>